package com.wlcorp.forcazamis.web.action.baseinfo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wlcorp.forcazamis.business.baseinfo.IFeatureService;
import com.wlcorp.forcazamis.domain.baseinfo.Feature;
import com.wlcorp.forcazamis.sys.util.AppConstant;
import com.wlcorp.forcazamis.sys.util.ContextUtil;
import com.wlcorp.forcazamis.sys.util.WebUtil;

public class FeatureAction extends DispatchAction {
	public ActionForward getFeatureList(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		List<Feature> featureList = ContextUtil.getInstance().getFeatureService().getFeatureList(null);
		request.setAttribute("featureList",featureList);
		return mapping.findForward("list");
	}
	
	public ActionForward getFeature(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		Feature feature = new Feature();
		WebUtil.setRequestToObject(request,feature);
		feature = ContextUtil.getInstance().getFeatureService().getFeatureById(feature.getFeatureId());
		if(null == feature){
			feature = new Feature();
		}
		request.setAttribute("feature",feature);
		return mapping.findForward("modify");
	}
	
	public ActionForward modifyFeature(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		Feature feature = new Feature();
		WebUtil.setRequestToObject(request,feature);
		ContextUtil.getInstance().getFeatureService().saveFeature(feature);
		if(AppConstant.BASE_BEAN_STATUS_ERROR == feature.getStatus()){
			WebUtil.setAlertMessage(request,feature.getMsg());
		}else{
			WebUtil.setAlertMessage(request,"操作成功！");
		}
		
		request.setAttribute("feature",feature);
		return mapping.findForward("modify");
	}
	
	public ActionForward deleteFeature(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		Feature feature = new Feature();
		WebUtil.setRequestToObject(request,feature);
		IFeatureService service = ContextUtil.getInstance().getFeatureService();
		feature = service.getFeatureById(feature.getFeatureId());
		if(null != feature){
			service.deleteFeature(feature);
		}
		return getFeatureList(mapping,form,request,response);
	}
}
